package java052;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

class User implements Comparable<User> {
	private int age;

	public User(int age) {
		this.age = age;
	}

	public int getAge() {
		return age;
	}

	@Override
	public int compareTo(User o) {

		return age - o.age;
	}

	@Override
	public String toString() {
		return "User [age=" + age + "]";
	}

}

class StuUser extends User {
	private String no;

	public StuUser(int age, String no) {
		super(age);
		this.no = no;
	}

	public String getNo() {
		return no;
	}

	@Override
	public String toString() {
		return "StuUser [no=" + no + ", toString()=" + super.toString() + "]";
	}

}

class UserReverseComparator implements Comparator<User> {

	@Override
	public int compare(User o1, User o2) {
		return o2.getAge() - o1.getAge();
	}

}

class StuUserComparator implements Comparator<StuUser> {

	@Override
	public int compare(StuUser o1, StuUser o2) {
		return o1.getNo().compareTo(o2.getNo());
	}
}
public class Main {
	public static void main(String[] args) {
		List<StuUser> stuList = new ArrayList<StuUser>();
        stuList.add(new StuUser(3, "1"));
        stuList.add(new StuUser(2, "2"));
        stuList.add(new StuUser(1, "3"));
        System.out.println(max1(stuList));
    }
    
    public static <stuCompare extends Comparable<StuUser>> StuUser max1(List<StuUser> stuList) {
        StuUser max1 = stuList.get(0);
        for(StuUser stu : stuList){
            if(stu.compareTo(max1)>0)
                max1 = stu;
        }
        return max1;
    }      
		/* List<String> strList = new ArrayList<String>();
		        List<Integer> intList = new ArrayList<Integer>();
		        strList.add("a");
		        strList.add("b");
		        strList.add("c");
		        intList.add(1);
		        intList.add(2);
		        intList.add(3);
		        String max = max(strList);
		        Integer maxInt = max(intList);
		        System.out.println("max = " + max);
		        System.out.println("maxInt =" + maxInt);
		    }
		    public static<T extends Comparable<T>>T max(List<T>list){
		        T max = list.get(0);
		        for(T i : list){
		            if(i.compareTo(max)>0)
		                max = i;
		        }
		        return max;
		    }*/
}